﻿namespace CodeDDD.Infrastructure.Crosscutting.Seedwork
{
    using System.Collections.Generic;

    /// <summary>
    /// Represents a validation error on an entity
    /// </summary>
    public class ValidationError
    {
        #region Fields

        IEnumerable<string> _memberNames;

        #endregion

        #region Properties

        readonly string ErrorMessage;
        IEnumerable<string> MemberNames { get { return _memberNames; } }

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a validation error that has no related members
        /// </summary>
        /// <param name="errorMessage"></param>
        public ValidationError(string errorMessage)
        {
            this.ErrorMessage = errorMessage;
        }

        /// <summary>
        /// Creates a validation error related to some members
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <param name="memberNames"></param>
        public ValidationError(string errorMessage, IEnumerable<string> memberNames)
            : this(errorMessage)
        {
            _memberNames = memberNames;
        }

        /// <summary>
        /// Creates a validation error related to a member
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <param name="memberName"></param>
        public ValidationError(string errorMessage, string memberName)
            : this(errorMessage, new string[] { memberName })
        {
        }

        #endregion
    }
}
